package com.qing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

import com.qing.service.LeaveService;
import com.qing.pojo.Leave;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qinghua
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/leave")
public class LeaveController {
    @Autowired
    private LeaveService leaveService;

    @PostMapping("/insert")
    public Boolean save(@RequestBody Leave leave) {
        return leaveService.saveOrUpdate(leave);
    }

    @GetMapping("/deleteById/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return leaveService.removeById(id);
    }

    @GetMapping("/queryAll")
    public List<Leave> queryAll() {
        return leaveService.list(new QueryWrapper<Leave>().orderByDesc("create_time"));
    }

    @GetMapping("/queryById/{id}")
    public Leave findOne(@PathVariable Integer id) {
        return leaveService.getById(id);
    }

    @GetMapping("/queryAllAndName")
    public List<Map<String, Object>> queryAllAndName(){
        return leaveService.queryAllAndName();
    }

    @GetMapping("/queryAllAndNameByEmployeeId/{id}")
    public List<Map<String, Object>> queryAllAndName(@PathVariable("id") Integer employeeId){
        return leaveService.queryAllAndNameByEmployeeId(employeeId);
    }

}

